package com.pos43.business.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.pos43.business.dao.IUserDao;
import com.pos43.domain.User;

public class UserDao extends HibernateDaoSupport implements IUserDao{

	public User get(Integer id){
		return getHibernateTemplate().get(User.class, id);
	}

	public Integer save(User product){
		return (Integer)getHibernateTemplate()
			.save(product);
	}
	
	public void update(User product){
		getHibernateTemplate().update(product);
	}
	
	public void delete(User product){
		getHibernateTemplate().delete(product);
	}
	
	public void delete(Integer id){
		getHibernateTemplate().delete(get(id));
	}
	
	public List<User> findAll(){
		return (List<User>)getHibernateTemplate()
				.find("from User");
	}

	@Override
	public List<User> findByParam(String key) {
		String hql = "from User u where u.username like '%" + key + "%'";
		return this.getSession()
				.createQuery(hql)
				.list();
		}

	@Override
	public List<User> get(User user) {
		return this.getSession()
				.createQuery("from User u where u.id=? and u.pwd=?")
				.setParameter(0, user.getId())
				.setParameter(1, user.getPwd())
				.list();
	}

}
